package com.artoxian.unused;
import java.io.File;
import java.util.Date;

import org.apache.commons.io.monitor.FileAlterationListener;
import org.apache.commons.io.monitor.FileAlterationObserver;
import org.apache.log4j.Logger;

public class FileAlterationListenerImpl implements FileAlterationListener {
	private static Logger log = Logger.getLogger(FileAlterationListenerImpl.class);
	
    /**
     * {@inheritDoc}
     */
    @Override
    public void onStart(final FileAlterationObserver observer) {
        log.info("FileListener started for " + observer.getDirectory().getAbsolutePath());
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    public void onDirectoryCreate(final File directory) {
        log.info(directory.getAbsolutePath() + " was created.");
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    public void onDirectoryChange(final File directory) {
        log.info(directory.getAbsolutePath() + " was modified.");
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    public void onDirectoryDelete(final File directory) {
        log.info(directory.getAbsolutePath() + " was deleted.");
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    public void onFileCreate(final File file) {
        log.info(file.getAbsoluteFile() + " was created.");
        
		/*try {
			// Get the connector
			GarminConnector connector = GarminConnector.getInstance();
			
			// Login
			connector.login(GarminProperties.getInstance().getUsername(), GarminProperties.getInstance().getPassword());
			
			// Upload the file
			connector.upload(file);
		} catch (IOException e) {
			log.error(e.getMessage(), e);
		} catch (GarminConnectorException e) {
			log.error(e.getMessage(), e);
		}*/
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    public void onFileChange(final File file) {
        log.info(file.getAbsoluteFile() + " was modified.");
        log.info("----------> length: " + file.length());
        log.info("----------> last modified: " + new Date(file.lastModified()));
        log.info("----------> readable: " + file.canRead());
        log.info("----------> writable: " + file.canWrite());
        log.info("----------> executable: " + file.canExecute());
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    public void onFileDelete(final File file) {
        log.info(file.getAbsoluteFile() + " was deleted.");
    }
 
    /**
     * {@inheritDoc}
     */
    @Override
    public void onStop(final FileAlterationObserver observer) {
        log.info("FileListener stopped for " + observer.getDirectory().getAbsolutePath());
    }
}